package com.example.yblin.hello24.DataUtils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * LocalDataUtil.java
 * Version:1.0
 * 本地数据工具类，使用ShardPreferences实现本地数据存储
 */

public class LocalDataUtil {

    //数据库名常量定义
    public static final String DATABASE_USERDATA = "userdata";
    //数据键名常量定义
    public static final String USERNAME = "username";//用户名
    public static final String PASSWORD = "password";//密码

    private static SharedPreferences data;

    public LocalDataUtil() {

    }

    public static String read(Context context, String database, String key) {
        data = context.getSharedPreferences(database, Context.MODE_PRIVATE);
        return data.getString(key, "");
    }

    public static void write(Context context, String database, String key, String value) {
        data = context.getSharedPreferences(database, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = data.edit();
        editor.putString(key, value);
        editor.apply();
    }
}
